using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Typing_GUI
{
    public partial class frmResultOfExam : Form
    {
        public frmResultOfExam()
        {
            InitializeComponent();
        }
        public int error, score, speed, time;
        public string examName;
        public int examID, userID;
        private void frmResultOfExam_Load(object sender, EventArgs e)
        {
            lblErrors.Text = error.ToString();
            lblScore.Text = score.ToString();
            lblSpeed.Text = speed + " (wpm)";
            lblTime.Text = (time / 60).ToString().PadLeft(2, '0') + ":" + (time % 60).ToString().PadLeft(2, '0'); ;
            lblExamName.Text = examName;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmResultOfExam_FormClosing(object sender, FormClosingEventArgs e)
        {

            CLASS.CKetQuaLuyenTap  examResult = new Typing_GUI.CLASS.CKetQuaLuyenTap();
            examResult.Matclt = examID;
            examResult.Manguoidung = userID;
            examResult.Soloisai = error;
            examResult.Thoigian = time;
            examResult.Tocdo = speed.ToString();
            if (!CLASS.CKetQuaLuyenTap.CheckExistResult(examID, userID))
                examResult.createResult();
            else
            {
                DialogResult result = MessageBox.Show("Your old score: " + CLASS.CKetQuaLuyenTap.GetExamResult(examID,userID).Diemdatduoc + "\n Your new score:" + score.ToString() + " \n Do you want to change it?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    examResult.updateResult();
                }
            }
        }
    }
}